home *** CD-ROM | disk | FTP | other *** search
- #include "TestDrvr.h"
- #include "TracksInfo.h"
- #include <Events.h> /* For keymap definition */
- #include <ToolUtils.h>
- #include <Errors.h>
- #include <Memory.h>>
- #include <Resources.h>
- #include <Devices.h>
- #include <types.h> // Mac types
- #include <Desk.h> /* for accRun */
- #include <Quickdraw.h>
-
- #include <Files.h>
-
-
- pascal short DrvrEntry(Globals *globals, short csCode, Ptr paramPtr, DCtlPtr dCtl)
- {
-
- short result = noErr;
-
-
- switch (csCode)
- {
-
- case kInstallTrace:
- globals->fTraceProcPtr = ((TraceDataPtr)paramPtr)->TraceProc;
- globals->fTraceArg = ((TraceDataPtr)paramPtr)->TraceGlobals;
- break;
-
- case kRemoveTrace:
- globals->fTraceProcPtr = nil;
- globals->fTraceArg = nil;
- break;
-
- case accRun: // Periodic Event
- globals->EventCount++;
-
- if (OPTION_KEY_DOWN())
- HandleOptKeyDown(globals);
- else
- if (CMD_KEY_DOWN())
- HandleCmdKeyDown(globals, dCtl);
-
- break;
- default:
- T_STACK(kStackPeekEx);
- T_PSTR(kUnexpectedErr, 0, "\pUnknown csCode");
-
- result = controlErr; // no such csCode
- break;
- }
-
- return(result);
- }
-
- void HandleOptKeyDown(Globals *globals)
- {
- /* This will record who called this routine. */
- T_STACK(kStackPeekEx); /* This will log that 'DrvrEntry' was called by 'TControl' */
-
- /* Log periodic event count */
- T_PSTRLONG(kOptKeyDown, 0, "\pEventCount = ", (long) globals->EventCount);
- T_PSTR(kOptKeyDown, 1, "\pKeyMap = ");
- T_DATA(kOptKeyDown, 2, theKeyMap, (long)sizeof(KeyMap));
-
- }
-
- void HandleCmdKeyDown(Globals *globals, DCtlPtr dCtl)
- {
- /* This will record who called this routine. */
- T_STACK(kStackPeekEx);
- // How to send formatted data. The template is defined in Macsbug's "Debugger Prefs"
- // file in resource 'mxwt' "Macsbug 6.2".
-
- T_TYPE(kCmdKeyDown, 0, dCtl, (long)sizeof(DCtlEntry), (long)"\pDCtlEntry");
- }
-
-
- OSErr TControl(CntrlParam *ctlPB, DCtlPtr dCtl)
- {
- register OSErr error;
- register short csCode;
- register Ptr paramPtr;
- register Globals *globals;
-
- // The dCtlStorage field in the DCE entry contains our globals pointer
-
- globals = (Globals *) dCtl->dCtlStorage;
- csCode = ctlPB->csCode;
-
- paramPtr = (Ptr)&(ctlPB->csParam);
-
- error = DrvrEntry(globals, csCode, paramPtr, dCtl);
-
- return(error);
-
- }
-
-
- OSErr TOpen(CntrlParam *ctlPB, DCtlPtr dCtl)
- {
- #pragma unused (ctlPB)
- register OSErr error;
- register Globals *globals;
-
- // The dCtlStorage field in the DCE entry is used to keep a pointer
- // to the global memory block. This will be nil on the first Open call.
-
- error = noErr;
- globals = (Globals *) dCtl->dCtlStorage;
-
- if (globals == nil)
- {
- // Allocate global storage as a non-relocatable block on the System Heap...
-
- globals = (Globals *) NewPtrSysClear(sizeof(Globals));
-
- if (globals == nil)
- error = MemError();
- else
- {
- // Save a pointer to the globals in the DCE:
- dCtl->dCtlStorage = (Handle) globals;
-
- // Init other driver specific globals...
- globals->EventCount = 0;
-
- }
- }
-
- return(error);
-
- }
-
-
- OSErr TPrime(CntrlParam *ctlPB, DCtlPtr dCtl)
- {
- #pragma unused (ctlPB, dCtl)
- return(readErr);
- }
-
- OSErr TStatus(CntrlParam *ctlPB, DCtlPtr dCtl)
- {
- register OSErr error;
- register short csCode;
- register Ptr paramPtr;
- register Globals *globals;
-
- // The dCtlStorage field in the DCE entry contains our globals pointer
-
- globals = (Globals *) dCtl->dCtlStorage;
- csCode = ctlPB->csCode;
-
- paramPtr = (Ptr)&(ctlPB->csParam);
-
- error = DrvrEntry(globals, csCode, paramPtr, dCtl);
-
- return(error);
-
- }
-
-
- OSErr TClose(CntrlParam *ctlPB, DCtlPtr dCtl)
- {
- #pragma unused (ctlPB,dCtl)
- return(closErr); // Not allowed to close this driver
- }
-
-